<!-- 专家评审意见 -->
<template>
  <el-descriptions
    :column="2"
    size="large"
    class="td-item"
    v-if="expertDetail?.reviewCategoryName"
  >
    <el-descriptions-item label-class-name="right-align" label="评审意见">
      <span class="text--info subtext">{{
        expertDetail.reviewCategoryName
      }}</span>
    </el-descriptions-item>

    <el-descriptions-item
      label-class-name="right-align"
      label="汇总专家评审意见"
    >
      <div
        v-if="expertDetail.reviewTemplateAttachmentArr?.length"
        class="file-wrap"
      >
        <p
          class="text--info download-link subtext"
          v-for="(obj, index) in expertDetail.reviewTemplateAttachmentArr"
          :key="index"
          @click.prevent="handlePreview(obj)"
        >
          <el-link :underline="false" icon="el-icon-folder">{{
            obj?.fileName
          }}</el-link>
        </p>
      </div>
      <div class="text--info subtext file-wrap" v-else>-</div>
    </el-descriptions-item>

    <el-descriptions-item label-class-name="right-align" label="备注">
      <span class="text--info subtext">{{ expertDetail.remark }}</span>
    </el-descriptions-item>
  </el-descriptions>
</template>

<script lang="ts" setup>
import { onMounted, ref, watch } from "vue";
import axios from "axios";
import { storageLocal } from "/@/utils/storage";
const props = defineProps({
  projectInfo: {
    type: Object
  }
});
const projectInfo = ref({});
const expertDetail = ref({});
const baseUrl = ref(import.meta.env.VITE_BASE_URL);
onMounted(() => {
  projectInfo.value = props.projectInfo;
  getExpertRoundList();
});

//查询专家审批轮次
const getExpertRoundList = async () => {
  const params = {
    projectManageId: projectInfo.value.projectManageId,
    reviewStageCode:
      projectInfo.value.reviewStageCode || projectInfo.value.stageStatus,
    pageSize: 100
  };
  const getExpertUrl = `${baseUrl.value}/rdms-admin/expertRvw/list`;
  const headers = {
    headers: { Authorization: storageLocal.getItem("rdms-info")?.accessToken }
  };
  try {
    const res = await axios.post(getExpertUrl, params, headers);
    if (res.status === 200) {
      if (res.data?.data?.list && res.data?.data?.list.length > 0) {
        expertDetail.value = res.data?.data?.list[0];
      } else {
        expertDetail.value = {};
      }
      console.log(
        expertDetail.value,
        "expertDetail.valueexpertDetail.valueexpertDetail.value"
      );
    }
  } catch (err) {
    console.log(err);
  }
};

const handlePreview = (item: any) => {
  if (item.response) {
    window.open(
      `${location.origin}${location.pathname}#/online?uuidFile=${item?.response.data.uuidFile}&fileName=${item?.response.data.fileName}`
    );
  } else {
    window.open(
      `${location.origin}${location.pathname}#/online?uuidFile=${item.uuidFile}&fileName=${item.fileName}`
    );
  }
};

watch(
  () => props.projectInfo,
  newvalue => {
    projectInfo.value = newvalue;
    if (newvalue.projectManageId) {
      getExpertRoundList();
    }
  }
);
</script>

<style lang="scss" scoped>
.file-wrap {
  display: inline-block;
  vertical-align: top;
}
.td-item {
  :deep .el-descriptions__cell {
    padding-bottom: 6px;
  }
}
</style>
